package com.palfund.mvp.home.presenter;

import android.os.Handler;

import com.palfund.mvp.home.contract.LoginContract;
import com.palfund.mvp.home.model.LoginListener;
import com.palfund.mvp.home.model.LoginModel;

/**
 * Created by clvc on 2017/8/17.
 * 真正的速度是看不见的 !
 * Today is today , we will go !
 */

public class LoginPresenter implements LoginContract.Presenter, LoginListener {
    private LoginContract.View mView;
    private Handler mHandler=new Handler();
    private LoginModel mModel;

    public LoginPresenter(LoginContract.View view) {
        view.setPresenter(this);
        mView = view;
        mModel = new LoginModel();
    }

    @Override
    public void start() {
        login();
    }

    @Override
    public void login() {
        mView.showProgress();
        mModel.login(mView.getName(), mView.getPassword(), this);

    }

    @Override
    public void successful() {
       mHandler.post(new Runnable() {
           @Override
           public void run() {
               mView.success();
               mView.hideProgress();
               mView.reset();
           }
       });
    }

    @Override
    public void failed() {
        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mView.failed();
                mView.hideProgress();
                mView.reset();
            }
        });
    }
}
